/**
 * Created by Administrator on 2019/5/21/021.
 */
import CZML_GENERALTOOLS_CLASS from "./../main/CZML_GENERALTOOLS_CLASS.js"
import CZML_CummunicationArc from "./CZML_CummunicationArc.js"
import CZML_PIXEL_CLASS from "../main/CZML_PIXEL_CLASS.js"

class PRIMITIVE_SpacecraftAnimatedModelOrbit {
  constructor(
    viewer,
    id,
    name,
    OrbitStartTime,
    OrbitEndTime,
    position,
    orientation,
    MarkerVisible,
    MarkerPath,
    MaekerPixelSize,
    MarkerColor,
    MarkerXOriginPos,
    MarkerYOriginPos,
    OrbitVisible,
    OrbitLineStyle,
    OrbitLineWidth,
    OrbitColor,
    ReferenceFrame
  ) {
    this._viewer = viewer
    this.id = id
    this.name = name
    this.OrbitStartTime = OrbitStartTime
    this.OrbitEndTime = OrbitEndTime
    this.position = position
    this.orientation = orientation
    this.MarkerVisible = MarkerVisible
    this.MarkerPath = MarkerPath
    this.MaekerPixelSize = MaekerPixelSize
    this.MarkerColor = MarkerColor
    this.MarkerXOriginPos = MarkerXOriginPos
    this.MarkerYOriginPos = MarkerYOriginPos
    this.OrbitVisible = OrbitVisible
    this.OrbitLineStyle = OrbitLineStyle
    this.OrbitLineWidth = OrbitLineWidth
    this.OrbitColor = OrbitColor
    this.ReferenceFrame = ReferenceFrame
    this.PRIMITIVE_AddSpacecraftAnimatedModelOrbit()
  }

  PRIMITIVE_AddSpacecraftAnimatedModelOrbit() {
    const sOrbitStartTime = CZML_GENERALTOOLS_CLASS.Utcg2ISO8601TimeTransformation(this.OrbitStartTime)
    const sOrbitEndTime = CZML_GENERALTOOLS_CLASS.Utcg2ISO8601TimeTransformation(this.OrbitEndTime)
    const AvailabilityTime = sOrbitStartTime + "/" + sOrbitEndTime
    const OrbitObject = {
      id: this.id,
      availability: AvailabilityTime,
      name: this.name,
      billboard: {
        eyeOffset: {
          cartesian: [0, 0, 0]
        },
        horizontalOrigin: this.MarkerXOriginPos,
        image: this.MarkerPath,
        pixelOffset: {
          cartesian2: [0, 0]
        },
        scale: this.MaekerPixelSize,
        show: this.MarkerVisible,
        verticalOrigin: this.MarkerYOriginPos
      },
      label: {
        fillColor: {
          rgba: this.MarkerColor
        },
        font: "11pt Lucida Console",
        horizontalOrigin: "LEFT",
        pixelOffset: {
          cartesian2: [10, 0]
        },
        show: this.MarkerVisible,
        style: "FILL_AND_OUTLINE",
        text: this.name,
        verticalOrigin: "CENTER"
      },
      path: {
        show: [
          {
            interval: CZML_GENERALTOOLS_CLASS.HEU_ScenarioTime,
            boolean: this.OrbitVisible
          }
        ],
        width: this.OrbitLineWidth,
        material: CZML_GENERALTOOLS_CLASS.GetMaterialObject(this.OrbitLineStyle, this.OrbitColor),
        resolution: 120
      },
      position: {
        interpolationAlgorithm: "LAGRANGE",
        interpolationDegree: 2,
        referenceFrame: this.ReferenceFrame,
        epoch: sOrbitStartTime,
        cartesian: this.position
      },
      orientation: {
        interpolationAlgorithm: "LAGRANGE",
        interpolationDegree: 1,
        epoch: sOrbitStartTime,
        unitQuaternion: this.orientation
      }
    }
    // 插入该数据对象
    CZML_GENERALTOOLS_CLASS.InsertModelObjectInformation(this.id, OrbitObject, true)
    // 添加轨道显示部分
    const idOther = [null]
    const vOrbitStartTime = [this.OrbitStartTime]
    const vOrbitEndTime = [this.OrbitEndTime]
    const pixel = new CZML_PIXEL_CLASS(this._viewer)
    pixel.CZML_PIXEL_AddCummunicationArc(this.id, idOther, this.OrbitVisible, vOrbitStartTime, vOrbitEndTime)
    // return CZML_GENERALTOOLS_CLASS.InsertModelObjectInformation(this.id, OrbitObject, true);
  }
}

export default PRIMITIVE_SpacecraftAnimatedModelOrbit
